package LatexForCorrelations;

import java.io.BufferedWriter;
import java.text.DecimalFormat;
import java.text.NumberFormat;

import Analysis.CorrelationManagerClass;
import Definitions.GraphClass;
import Global.ConstantVariable;

public class LatexUtilityForDatasetsCorrelations {
	
	public static class datasetCorrelationsTableCreatorClass
	{
		public static void printLatexDatasetCorrelationsTableToTheFileInMatrixFormat(BufferedWriter out, GraphClass graph, String datasetName, CorrelationManagerClass correlationManager)
		{
			try
			{
				NumberFormat formatter;
				
				formatter = new DecimalFormat(ConstantVariable.Format_ConstantVariables.numberFormatToBeUsedForCorrelationsLatexTable);
								
				//double cor_kCO_hCO = CorrelationCalculatorClass.calculatePearsonCorrelation(graph.getPropertiesOfTheGraphWithRespectToEdgeType().prepareForCorrelationCalculation((degreeDistributionRelatedPropsCO.getDegreeListOfNodes()),graph.getPropertiesOfTheGraphWithRespectToEdgeType().prepareForCorrelationCalculation( homophilyRelatedPropsCO.getHomophilyListOfTheNodes())));
				
				out.write("\\begin{table}%[ht])");
				out.write("\n");
				out.write("\\centering");
				out.write("\n");
				out.write("\\caption{");
				out.write(datasetName.replace('_', '-'));
				out.write(" Correlations Results}");				
				out.write("\n");
				out.write("\\begin{tabular}{|c|c|c|c|c|}");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
				out.write("D. No & c(CO)& h(CO) & A(CO)& a(CO) \\\\");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
				
				out.write("k(CO) &" + formatter.format(correlationManager.correlations.getCor_kCO_cCO())+ "& "+ formatter.format(correlationManager.correlations.getCor_kCO_hCO())+ "& "+ formatter.format(correlationManager.correlations.getCor_kCO_alphaCO())+ "& "+ formatter.format(correlationManager.correlations.getCor_kCO_accuracyCO())+"\\\\");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
				
				out.write("c(CO) & - & " + formatter.format(correlationManager.correlations.getCor_cCO_hCO())+ "& "+ formatter.format(correlationManager.correlations.getCor_cCO_alphaCO())+ "& "+ formatter.format(correlationManager.correlations.getCor_cCO_accuracyCO())+"\\\\");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
				
				out.write("h(CO) & - & - &" + formatter.format(correlationManager.correlations.getCor_hCO_alphaCO())+ "& "+ formatter.format(correlationManager.correlations.getCor_hCO_accuracyCO())+"\\\\");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
				
				out.write("A(CO) & - & - & - &" + formatter.format(correlationManager.correlations.getCor_alphaCO_accuracyCO())+"\\\\");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
				
				out.write("\\end{tabular}");
				out.write("\n");			
				out.write("\\label{table:");
				out.write(datasetName);
				out.write("Content Only Correlations}");
				out.write("\n");
				out.write("\\end{table}");
				out.write("\n");
				out.write("\n");
				out.write("\n");
				out.write("\n");
				out.write("\n");
				out.write("\n");
				
				out.write("\\begin{table}%[ht])");
				out.write("\n");
				out.write("\\centering");
				out.write("\n");
				out.write("\\caption{");
				out.write(datasetName.replace('_', '-'));
				out.write("Link Only Correlations Results}");				
				out.write("\n");
				out.write("\\begin{tabular}{|c|c|c|c|c|}");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
				out.write("D. No & c(LO)& h(LO) & A(LO)& a(LO) \\\\");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
				
				out.write("k(LO) &" + formatter.format(correlationManager.correlations.getCor_kLO_cLO())+ "& "+ formatter.format(correlationManager.correlations.getCor_kLO_hLO())+ "& "+ formatter.format(correlationManager.correlations.getCor_kLO_alphaLO())+ "& "+ formatter.format(correlationManager.correlations.getCor_kLO_accuracyLO())+"\\\\");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
				
				out.write("c(LO) & - & " + formatter.format(correlationManager.correlations.getCor_cLO_hLO())+ "& "+ formatter.format(correlationManager.correlations.getCor_cLO_alphaLO())+ "& "+ formatter.format(correlationManager.correlations.getCor_cLO_accuracyLO())+"\\\\");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
				
				out.write("h(LO) & - & - &" + formatter.format(correlationManager.correlations.getCor_hLO_alphaLO())+ "& "+ formatter.format(correlationManager.correlations.getCor_hLO_accuracyLO())+"\\\\");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
				
				out.write("A(LO) & - & - & - &" + formatter.format(correlationManager.correlations.getCor_alphaLO_accuracyLO())+"\\\\");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");

				
				out.write("\\end{tabular}");
				out.write("\n");			
				out.write("\\label{table:");
				out.write(datasetName);
				out.write("Link Only Correlations}");
				out.write("\n");
				out.write("\\end{table}");
				out.write("\n");
				out.close();
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}

		}
		
		
		public static void printLatexDatasetCorrelationsTableToTheFileInComboMatrixFormat(BufferedWriter out, GraphClass graph, String datasetName, CorrelationManagerClass correlationManager)
		{
			/*BufferedWriter out;

		FileWriter fstream = new FileWriter(fileAdditionalProperties);
	    BufferedWriter out = new BufferedWriter(fstream);*/

			try
			{
				
				
				NumberFormat formatter;
				
				formatter = new DecimalFormat(ConstantVariable.Format_ConstantVariables.numberFormatToBeUsedForCorrelationsLatexTable);
								
				//double cor_kCO_hCO = CorrelationCalculatorClass.calculatePearsonCorrelation(graph.getPropertiesOfTheGraphWithRespectToEdgeType().prepareForCorrelationCalculation((degreeDistributionRelatedPropsCO.getDegreeListOfNodes()),graph.getPropertiesOfTheGraphWithRespectToEdgeType().prepareForCorrelationCalculation( homophilyRelatedPropsCO.getHomophilyListOfTheNodes())));
				
				out.write("\\begin{table}%[ht])");
				out.write("\n");
				out.write("\\centering");
				out.write("\n");
				out.write("\\caption{");
				out.write(datasetName.replace('_', '-'));
				out.write(" Correlations Results}");				
				out.write("\n");
				out.write("\\begin{tabular}{|c|c|c|c|c|c|c|c|c|c|}");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
				out.write("D. No & c(CO)& h(CO) & a(CO)& A(CO) & k(LO) & c(LO)& h(LO) & A(LO)& a(LO) \\\\");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
				
				out.write("k(CO) &" + formatter.format(correlationManager.correlations.getCor_kCO_cCO())+ "& "+ formatter.format(correlationManager.correlations.getCor_kCO_hCO())+ "& "+ formatter.format(correlationManager.correlations.getCor_kCO_alphaCO())+ "& "+ formatter.format(correlationManager.correlations.getCor_kCO_accuracyCO()) + "& " + formatter.format(correlationManager.correlations.getCor_kCO_kLO())+ "& " + formatter.format(correlationManager.correlations.getCor_kCO_cLO())+ "& " + formatter.format(correlationManager.correlations.getCor_kCO_hLO())+ "& " + formatter.format(correlationManager.correlations.getCor_kCO_alphaLO())+ "& " + formatter.format(correlationManager.correlations.getCor_kCO_accuracyLO())+"\\\\");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
				
				out.write("c(CO) & - & " + formatter.format(correlationManager.correlations.getCor_cCO_hCO())+ "& "+ formatter.format(correlationManager.correlations.getCor_cCO_alphaCO())+ "& "+ formatter.format(correlationManager.correlations.getCor_cCO_accuracyCO())+ "& " + formatter.format(correlationManager.correlations.getCor_cCO_kLO())+ "& " + formatter.format(correlationManager.correlations.getCor_cCO_cLO())+ "& " + formatter.format(correlationManager.correlations.getCor_cCO_hLO())+ "& " + formatter.format(correlationManager.correlations.getCor_cCO_alphaLO()) + "& " + formatter.format(correlationManager.correlations.getCor_cCO_accuracyLO())+"\\\\");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
				
				out.write("h(CO) & - & - &" + formatter.format(correlationManager.correlations.getCor_hCO_alphaCO())+ "& "+ formatter.format(correlationManager.correlations.getCor_hCO_accuracyCO())+ "& " + formatter.format(correlationManager.correlations.getCor_hCO_kLO())+ "& " + formatter.format(correlationManager.correlations.getCor_hCO_cLO())+ "& " + formatter.format(correlationManager.correlations.getCor_hCO_hLO())+ "& " + formatter.format(correlationManager.correlations.getCor_hCO_alphaLO())+ "& " + formatter.format(correlationManager.correlations.getCor_hCO_accuracyLO())+"\\\\");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
				
				out.write("A(CO) & - & - & - &" + formatter.format(correlationManager.correlations.getCor_alphaCO_accuracyCO())+ "& " +formatter.format(correlationManager.correlations.getCor_alphaCO_kLO())+ "& " + formatter.format(correlationManager.correlations.getCor_alphaCO_cLO())+ "& " + formatter.format(correlationManager.correlations.getCor_alphaCO_hLO())+ "& " + formatter.format(correlationManager.correlations.getCor_alphaCO_alphaLO())+ "& " + formatter.format(correlationManager.correlations.getCor_alphaCO_accuracyLO())+"\\\\");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
				
				out.write("a(CO) & - & - & - & - &" + formatter.format(correlationManager.correlations.getCor_accuracyCO_kLO())+ "& " + formatter.format(correlationManager.correlations.getCor_accuracyCO_cLO())+ "& " + formatter.format(correlationManager.correlations.getCor_accuracyCO_hLO())+ "& " + formatter.format(correlationManager.correlations.getCor_accuracyCO_alphaLO())+ "& " + formatter.format(correlationManager.correlations.getCor_accuracyCO_accuracyLO())+"\\\\");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
				
				out.write("k(LO) & - & - & - & - & -&" + formatter.format(correlationManager.correlations.getCor_kLO_cLO())+ "& " + formatter.format(correlationManager.correlations.getCor_kLO_hLO())+ "& " + formatter.format(correlationManager.correlations.getCor_kLO_alphaLO())+ "& " + formatter.format(correlationManager.correlations.getCor_kLO_accuracyLO())+"\\\\");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
				
				out.write("c(LO) & - & - & - & - & - & - &" + formatter.format(correlationManager.correlations.getCor_cLO_hLO())+ "& " + formatter.format(correlationManager.correlations.getCor_cLO_alphaLO())+ "& " + formatter.format(correlationManager.correlations.getCor_cLO_accuracyLO())+"\\\\");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
				
				out.write("h(LO) & - & - & - & - & - & - & - &" + formatter.format(correlationManager.correlations.getCor_hLO_alphaLO())+ "& " + formatter.format(correlationManager.correlations.getCor_hLO_accuracyLO())+"\\\\");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
				
				out.write("a(LO) & - & - & - & - & - & - & - & - &" + formatter.format(correlationManager.correlations.getCor_alphaLO_accuracyLO())+"\\\\");
				out.write("\n");
				out.write("\\hline");
				out.write("\n");
				
				out.write("\\end{tabular}");
				out.write("\n");			
				out.write("\\label{table:");
				out.write(datasetName);
				out.write("Content &Link Only Correlations}");
				out.write("\n");
				out.write("\\end{table}");
				out.close();
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}

		}
	}	
}
